//
//  KLCurrencyPickerCell.m
//  KLCurrency
//
//  Created by apple on 2017/12/4.
//  Copyright © 2017年 bonc. All rights reserved.
//

#import "KLCurrencyPickerCell.h"

#import "KLCurrencyEntity.h"

@interface KLCurrencyPickerCell ()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *locationImageView;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@end

@implementation KLCurrencyPickerCell


+ (instancetype)cellWithTableView:(UITableView *)tableView {
    KLCurrencyPickerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"picker"];
    return cell;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
}

- (void)setCurrencyEntity:(KLCurrencyEntity *)currencyEntity {
    _currencyEntity = currencyEntity;
    
    self.titleLabel.text =  [NSString stringWithFormat:@"%@ %@",currencyEntity.name, currencyEntity.abbreviation];
    [self.titleLabel sizeToFit];
    
    if (currencyEntity.isLocal) {
        //这边进行定位判断
        self.locationImageView.hidden = NO;
    } else {
        self.locationImageView.hidden = YES;
    }
    
    if (currencyEntity.changing) {
        self.statusLabel.text = @"当前选择";
//        self.userInteractionEnabled = NO;
    } else if (currencyEntity.main) {
        self.statusLabel.text = @"已选择";
//        self.userInteractionEnabled = NO;
    } else {
        self.statusLabel.text = @"";
//        self.userInteractionEnabled = YES;
    }
}

//复用清空资源
- (void)prepareForReuse {
    [super prepareForReuse];
    self.textLabel.text = nil;
    self.statusLabel.text = nil;
    self.locationImageView.hidden = YES;
    self.userInteractionEnabled = YES;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
